package com.gem.service.impl;

import com.gem.domain.Campus;
import com.gem.domain.CampusVisit;
import com.gem.mapper.CampusVisitMapper;
import com.gem.service.CampusVisitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 玲
 * @Description:
 * @create 2019-10-16 16:17
 * @Modified By:
 */
@Service
@SuppressWarnings("all")
@Transactional(rollbackFor=Exception.class)
public class CampusVisitServiceImpl implements CampusVisitService {

    @Autowired
    private CampusVisitMapper campusVisitMapper;

    @Override
    public int save(CampusVisit campusVisit) {
        return campusVisitMapper.save(campusVisit);
    }

    @Override
    public List<CampusVisit> findAllCampusVisit() {
        return campusVisitMapper.findAll();
    }

    @Override
    public PageInfo<CampusVisit> findAll( int currentPage,int pageSize) {
        PageInfo<CampusVisit> pageInfo = null;
        try {System.out.println();
            PageHelper.startPage(currentPage,pageSize);
            pageInfo =new PageInfo<>(campusVisitMapper.findAll());
        }catch (Exception e){
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public int deleteById(Integer campusVisitId) {
        return campusVisitMapper.deleteById(campusVisitId);
    }

    @Override
    public int update(CampusVisit campusVisit) {
        return campusVisitMapper.update(campusVisit);
    }

    @Override
    public CampusVisit findById(Integer campusVisitId) {
        return campusVisitMapper.findById(campusVisitId);
    }

    @Override
    public PageInfo<CampusVisit> search(CampusVisit campusVisit,int currentPage, int pageSize) {
        //去除空格
        if (campusVisit.getCampusName()!=null){
            if ("null".equals(campusVisit.getCampusName())||campusVisit.getCampusName().length()==0){
                campusVisit.setCampusName(null);
            }else {
                campusVisit.setCampusName(campusVisit.getCampusName().replaceAll(" ",""));
                campusVisit.setCampusName("%"+campusVisit.getCampusName()+"%");
            }
        }
        if (campusVisit.getPersonname() != null) {
            if ("null".equals(campusVisit.getPersonname())||campusVisit.getPersonname().length()==0){
                campusVisit.setPersonname(null);
            }else {
                campusVisit.setPersonname(campusVisit.getPersonname().replaceAll(" ",""));
                campusVisit.setPersonname("%"+campusVisit.getPersonname()+"%");
            }
        }

        PageInfo<CampusVisit> pageInfo = null;
        try {
            PageHelper.startPage(currentPage,pageSize);
            pageInfo =new PageInfo<>(campusVisitMapper.search(campusVisit));
        }catch (Exception e){
            e.printStackTrace();
        }
        return pageInfo;

    }

    @Override
    public List<Integer> findGemPersons() {
        return campusVisitMapper.findGemPersons();
    }

    @Override
    public Integer findByGemPerson(Integer gemPerson) {
        return campusVisitMapper.findByGemPerson(gemPerson);
    }

    @Override
    public List<String> findCampus() {
        return campusVisitMapper.findCampus();
    }

    @Override
    public Integer findByCampus(String campus) {
        return campusVisitMapper.findByCampus(campus);
    }

    @Override
    public Integer findByGemPersonWeek(Integer gemPerson) {
        return campusVisitMapper.findByGemPersonWeek(gemPerson);
    }

    @Override
    public Integer findByCampusWeek(String campus) {
        return campusVisitMapper.findByCampusWeek(campus);
    }

    @Override
    @Transactional
    public Integer deleteAll(int[] campusVisitIds) {
        Integer result = campusVisitMapper.deleteAll(campusVisitIds);
        return result;
    }
}
